#include <bits/stdc++.h>

#define eb emplace_back
#define ep emplace
#define fi first
#define se second
#define in read<int>()
#define rep(i, x, y) for(int i = (x); i <= (y); i++)
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using pii = pair < int, int >;

template < typename T > T read() {
	T x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-', ch = getchar();
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar();
	return f ? -x : x;
}

const int N = 1010;
const pii H[4] = {{ 1, 0 }, { -1, 0 }, { 0, 1 }, { 0, -1 }};

char s[N][N];
int bel[N][N], ps[3][N][N], px[N * N], py[N * N], tot, n, m, Q;
bool vis[N * N];

bool inmap(int x, int y, int lx = 1, int ly = 1, int rx = n, int ry = m) { return x >= lx && x <= rx && y >= ly && y <= ry; }
int getsum(int s[N][N], int lx, int ly, int rx, int ry) { return s[rx][ry] + s[lx - 1][ly - 1] - s[lx - 1][ry] - s[rx][ly - 1]; }
bool conn(int a, int b, int c, int d) {
	if(a == c) return s[a][max(b, d)] != s[a + 1][max(b, d)];
	else return s[max(a, c)][b] != s[max(a, c)][b + 1];
}

void calc(int sx, int sy) {
	++tot; bel[sx][sy] = tot; queue < pii > q; q.ep(sx, sy); int x, y; px[tot] = sx; py[tot] = sy; ps[2][sx][sy] = 1; bool tfl = 0;
	while(q.size()) {
		auto v = q.front(); q.pop(); tie(x, y) = v;
		rep(i, 0, 3) {
			int nx = x + H[i].fi, ny = y + H[i].se;
			if(conn(x, y, nx, ny) && (nx < 1 || ny < 1 || nx >= n || ny >= m)) tfl = true;
			if(inmap(nx, ny, 1, 1, n - 1, m - 1) && conn(x, y, nx, ny) && !bel[nx][ny]) 
				bel[nx][ny] = tot, q.ep(nx, ny);
		}
	} if(tfl) px[tot] = py[tot] = 0, ps[2][sx][sy] = 0;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	n = in, m = in, Q = in;
	rep(i, 1, n) scanf("%s", s[i] + 1);
	rep(i, 1, n - 1) rep(j, 1, m) if(s[i][j] == s[i + 1][j]) ps[0][i][j] = 1;
	rep(i, 1, n) rep(j, 1, m - 1) if(s[i][j] == s[i][j + 1]) ps[1][i][j] = 1;
	rep(i, 1, n - 1) rep(j, 1, m - 1) if(!bel[i][j]) calc(i, j);
	
	rep(t, 0, 2) rep(i, 1, n) rep(j, 1, m) ps[t][i][j] += ps[t][i - 1][j] + ps[t][i][j - 1] - ps[t][i - 1][j - 1];
	
	rep(_, 1, Q) {
		int lx = in, ly = in, rx = in, ry = in;
		int V = (rx - lx + 1) * (ry - ly + 1), F = getsum(ps[2], lx, ly, rx - 1, ry - 1),
			E = getsum(ps[0], lx, ly, rx - 1, ry) + getsum(ps[1], lx, ly, rx, ry - 1);
		auto ip = [&](int id) { return inmap(px[id], py[id], lx, ly, rx - 1, ry - 1); };
		rep(i, lx, rx) if(!vis[bel[i][ly - 1]] && ip(bel[i][ly - 1])) vis[bel[i][ly - 1]] = true, F--;
		rep(i, lx, rx) if(!vis[bel[i][ry]] && ip(bel[i][ry])) vis[bel[i][ry]] = true, F--;
		rep(i, ly, ry) if(!vis[bel[rx][i]] && ip(bel[rx][i])) vis[bel[rx][i]] = true, F--;
		//		cerr << V << " " << F << " " << E << endl;
		printf("%d\n", V + F - E);
		rep(i, lx, rx) vis[bel[i][ly - 1]] = vis[bel[i][ry]] = false;
		rep(i, ly, ry) vis[bel[rx][i]] = false;
	}
	return 0;
}
